// run: $exec < input
#include <cstdio>
#include <utility>
#include <algorithm>
#include <queue>

int const maxn = 100007;
int const inf = 1 << 30;
int head[maxn], end_point[2 * maxn], next[2 * maxn];
int alloc = 2;

struct priority_queue
{
	void push(int x) { q.push(x); }
	void erase(int x) { del.push(x); }
	int size() const { return q.size() - del.size(); }

	void pop()
	{
		while (del.size() && del.top() == q.top()) {
			del.pop(); q.pop();
		}
		q.pop();
	}

	int top()
	{
		while (del.size() && del.top() == q.top()) {
			del.pop(); q.pop();
		}
		return q.top();
	}

	int second_top()
	{
		int tmp = top(); pop();
		int ret = top(); push(tmp);
		return ret;
	}

	private:
	std::priority_queue<int> q, del;
};

priority_queue s1[maxn], s2[maxn], ans;

int log_2[2 * maxn], depth[maxn], pos[maxn], st[2 * maxn][20];
int tick;
int father[maxn];
bool centroid[maxn];
int subtree_size[maxn];
bool on[maxn];
int n, m;

void add_edge(int u, int v)
{
	end_point[alloc] = v; next[alloc] = head[u]; head[u] = alloc++;
	end_point[alloc] = u; next[alloc] = head[v]; head[v] = alloc++;
}

int calc_subtree_size(int u, int f)
{
	int ret = 1;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (centroid[v] || v == f) continue;
		ret += calc_subtree_size(v, u);
	}
	return subtree_size[u] = ret;
}

std::pair<int, int> get_center(int u, int f, int all)
{
	std::pair<int, int> ret(inf, 0); // FIXME origin(inf, -1), watch out range
	int max_sub = 0, sum = 1;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (v == f || centroid[v]) continue;
		max_sub = std::max(max_sub, subtree_size[v]);
		sum += subtree_size[v];
		ret = std::min(ret, get_center(v, u, all));
	}
	max_sub = std::max(max_sub, all - sum);
	return std::min(ret, std::make_pair(max_sub, u));
}

void get_dis(int u, int f, int dep, priority_queue & s)
{
	s.push(dep);
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (centroid[v] || v == f) continue;
		get_dis(v, u, dep + 1, s);
	}
}

int lca(int u, int v)
{
	u = pos[u]; v = pos[v];
	if (u > v) std::swap(u, v);
	int l = log_2[v - u + 1];
	return std::min(st[u][l], st[v - (1 << l) + 1][l]);
}

int distance(int u, int v)
{
	return depth[u] + depth[v] - 2 * lca(u, v);
}

void update_ans(priority_queue & s, bool add)
{
	if (s.size() >= 2) {
		if (add)
			ans.push(s.top() + s.second_top());
		else
			ans.erase(s.top() + s.second_top());
	}
}

int divide_and_conquer_for_tree(int u)
{
	int center = get_center(u, 0, calc_subtree_size(u, 0)).second;
	centroid[center] = true;
	s2[center].push(0);
	for (int p = head[center]; p; p = next[p]) {
		int v = end_point[p];
		if (centroid[v]) continue;
		priority_queue ts;
		get_dis(v, 0, 1, ts);
		int tmp = divide_and_conquer_for_tree(v);
		father[tmp] = center;
		s1[tmp] = ts;
		s2[center].push(s1[tmp].top());
	}
	update_ans(s2[center], true);
	return center;
}

void toggle(int x, bool on/* state now */)
{
	update_ans(s2[x], false);
	if (on) s2[x].push(0);
	else s2[x].erase(0);
	update_ans(s2[x], true);
	for (int i = x; father[i]; i = father[i]) {
		update_ans(s2[father[i]], false);
		if (s1[i].size())
			s2[father[i]].erase(s1[i].top());

		if (on) s1[i].push(distance(father[i], x));
		else s1[i].erase(distance(father[i], x));

		if (s1[i].size())
			s2[father[i]].push(s1[i].top());
		update_ans(s2[father[i]], true);
	}
}

void dfs(int u, int f)
{
	st[pos[u] = ++tick][0] = depth[u] = depth[f] + 1;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (v == f) continue;
		dfs(v, u);
		st[++tick][0] = depth[u];
	}
}

void init_lca()
{
	dfs(1, 0);
	for (int i = 2; i <= tick; i++)
		log_2[i] = log_2[i / 2] + 1;
	// init st
	for (int j = 1; j <= log_2[tick]; j++)
		for (int i = 1; i + (1 << j) - 1 <= tick; i++)
			st[i][j] = std::min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}

int main()
{
	std::scanf("%d", &n);
	int count_off = n;
	for (int i = 1, x, y; i < n; i++) {
		std::scanf("%d%d", &x, &y);
		add_edge(x, y);
	}

	divide_and_conquer_for_tree(1);

	init_lca();

	std::scanf("%d", &m);
	for (int i = 0, x; i < m; i++) {
		char ch[10];
		std::scanf("%s", ch);
		if (ch[0] == 'G') {
			if (count_off <= 1) std::printf("%d\n", count_off - 1);
			else std::printf("%d\n", ans.top());
		} else {
			std::scanf("%d", &x);
			toggle(x, on[x]);
			count_off += 2 * on[x] - 1;
			on[x] ^= true;
		}
	}
}

